﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DATA
{
        public   class HiddenQuestionREP
    {
        MODELGENERALDataContext context = new MODELGENERALDataContext();


        public List<HiddenQuestion> GetAllHiddenQuestions()
        {
            List<HiddenQuestion> acc = new List<HiddenQuestion>();

            var acounts = from a in context.HiddenQuestions
                          select a;
            foreach (var account in acounts)
            {
                acc.Add(account);
            }
            return acc;
        }

        public List<HiddenQuestion> GetActiveHiddenQuestion()
        {
            List<HiddenQuestion> acc = new List<HiddenQuestion>();

            var acounts = from a in context.HiddenQuestions

                          select a;
            foreach (var account in acounts)
            {
                acc.Add(account);
            }
            return acc;
        }

        public bool CheckDuplicate(int AccountID)
        {
            HiddenQuestion newacc = new HiddenQuestion();

            for (int i = 0; i < (int)(context.HiddenQuestions.Count()); i++)
            {
                HiddenQuestion acc = context.HiddenQuestions.Single(c => c == newacc);
                if (AccountID.Equals(acc.hqID))
                {
                    return true;
                }




            }
            return false;
        }

        public bool AddHiddenQuestion(HiddenQuestion newAccount)
        {
            HiddenQuestion newacc = new HiddenQuestion();
            HiddenQuestion acc = context.HiddenQuestions.Single(c => c == newacc);
            if (CheckDuplicate(newAccount.hqID) == false)
            {
                context.HiddenQuestions.InsertOnSubmit(acc);

                context.SubmitChanges();
            }

            return true;

        }
        public void deleteHiddenQuestion(int AccountID)
        {
            var acc = from c in context.HiddenQuestions
                      where c.hqID == AccountID
                      select c;

            context.HiddenQuestions.DeleteAllOnSubmit(acc);
            context.SubmitChanges();


        }

        public bool UpdateHiddenQuestion(HiddenQuestion accountup)
        {
            try
            {
                HiddenQuestion acc = context.HiddenQuestions.Single(
                                                        nv => nv.hqID == accountup.hqID
                                                        );
                acc.question = accountup.question;
                acc.isActived = accountup.isActived;

              


                context.SubmitChanges();
            }

            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }
    }
}
